package org.openharmony.qttool.qml.language;

import com.intellij.lang.ASTNode;
import com.intellij.lang.ParserDefinition;
import com.intellij.lang.PsiParser;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.project.Project;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.openharmony.qttool.language.QmlParser;
import org.openharmony.qttool.qml.grammar._QmlLexer;
import org.openharmony.qttool.qml.language.psi.QmlFile;
import org.openharmony.qttool.qml.language.QmlTypes;

class QmlParserDefinition implements ParserDefinition {

    private static final IFileElementType FILE = new IFileElementType(QmlLanguage.getInstance());


    @Override
    public @NotNull Lexer createLexer(Project project) {
        return new QmlLexerAdapter();
    }

    @Override
    public @NotNull PsiParser createParser(Project project) {
        return new QmlParser();
    }

    @Override
    public @NotNull IFileElementType getFileNodeType() {
        return FILE;
    }

    @Override
    public @NotNull TokenSet getCommentTokens() {
        return TokenSet.create(QmlTypes.LINE_COMMENT);
    }

    @Override
    public @NotNull TokenSet getStringLiteralElements() {
        return TokenSet.EMPTY;
    }

    @Override
    public @NotNull PsiElement createElement(ASTNode astNode) {
        return QmlTypes.Factory.createElement(astNode);
    }

    @Override
    public @NotNull PsiFile createFile(@NotNull FileViewProvider fileViewProvider) {
        return new QmlFile(fileViewProvider);
    }
}
